package com.common.util.javers;

import lombok.extern.log4j.Log4j;
import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
import org.springframework.beans.factory.FactoryBean;

/**
 * Javers spring
 */
@Log4j
public class JaversFactory implements FactoryBean<Javers> {

    public static InMemoryRepository inMemoryRepository=new InMemoryRepository();


    public static Javers getJavers() {
        Javers javers = JaversBuilder.javers()
                .registerJaversRepository(inMemoryRepository)
//                .withMappingStyle(MappingStyle.BEAN)
                .build();
        return javers;
    }

    @Override
    public Javers getObject() {
        Javers javers = JaversBuilder.javers()
                .registerJaversRepository(inMemoryRepository)
//                .withMappingStyle(MappingStyle.BEAN)
                .build();
        return javers;
    }

    @Override
    public Class<?> getObjectType() {
        return Javers.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
